from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options


class Login():
    def __init__(self, driver):  # 定义一个初始化
        self.driver = driver

    def login(self, username, pwd):
        # 登录
        self.driver.find_element(By.ID, 'ls_username').clear()
        self.driver.find_element(By.ID, 'ls_username').send_keys(username)
        self.driver.find_element(By.ID, 'ls_password').clear()
        self.driver.find_element(By.ID, 'ls_password').send_keys(pwd)
        sleep(3)
        self.driver.find_element(By.XPATH, '//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
        sleep(3)

    def loginout(self):
        # 退出
        self.driver.find_element(By.LINK_TEXT, '退出').click()
        sleep(3)


if __name__ == '__main__':
    url = r'http://192.168.226.131/upload/'
    username = 'test01'
    pwd = '123456'
    driver = webdriver.Chrome(options=options)  # 初始化谷歌浏览器对象
    driver.get(url)
    driver.maximize_window()

    login = Login(driver)
    login.login(username,pwd)
    login.loginout()
